from rest_framework import serializers
from orders.models import OrderInfo, OrderGoods, SKU


class OrdersSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = ('order_id', 'create_time')


class SKUSerializer(serializers.ModelSerializer):
    '''
    SKU序列化器
    '''

    class Meta:
        model = SKU
        fields = ('name', 'default_image')


class OrderGoodsSerializer(serializers.ModelSerializer):
    '''
    订单商品表序列化器
    '''
    sku = SKUSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = ('count', 'price','sku')


class OrderSerializer(serializers.ModelSerializer):
    '''
    订单表序列化器
    '''
    user_id=serializers.IntegerField()
    user = serializers.StringRelatedField(read_only=True)
    skus = OrderGoodsSerializer(read_only=True,many=True)

    class Meta:
        model = OrderInfo
        # fields='__all__'
        exclude = ('address',)
